'''
Created on May 26, 2012

@author: nathando
'''
import logging
import json
from entity.entity import Event
from entity.entity import UserEventList
from web import base
from web import urls
from web import util
from web import settings
from web.base import BaseHandler

class CreateListHandler(BaseHandler):
    @base.user_required
    def get(self):
        event_id = self.request.params.get('id')
        event = Event.get_by_id(int(event_id))
        user = util.get_current_user_key()
        
        # Add event id to watch list 
        if (event is not None and user is not None):
            exist = (UserEventList.query(UserEventList.user==user,UserEventList.event==event.key).count()>0)
            if (not exist):
                watch_list = UserEventList()
                watch_list.user = user
                watch_list.event = event.key
                watch_list.list_type = settings.LIST_WATCH
                key = watch_list.put()
                # Return the id back to client
                self.response.write(key)

app = urls.app

def main():
    app.run()

if __name__ == '__main__':
    main()